#lang racket

(define (runtime) (current-milliseconds))
(define (smallest-divisor n) 
  (find-divisor n 2))

(define (devides? a b)
  (= (remainder b a) 0))

(define (square x) (* x x))

(define (find-divisor n test-divisor)
  (cond ((> (square test-divisor) n) n)
        ((devides? test-divisor n) test-divisor)
        (else (find-divisor n (+ test-divisor 1)))))

(define (prime? n) (= n (smallest-divisor n)))

(define (timed-prime-test n) 
  (newline)
  (display n)
  (start-prime-test n (runtime)))

(define (start-prime-test n start-time)
  (cond ((prime? n)
         (report-prime (- (runtime) start-time)))))

(define (report-prime elapsed-time)
  (display " *** ")
  (display elapsed-time))

(define (search-for-primes a b)
  (define (test-and-proceed)
    (cond ((odd? a) (timed-prime-test a)))
    (search-for-primes (+ a 1) b))
  (cond ((or (< a b) (= a b)) (test-and-proceed))))

(search-for-primes 1000 2000)